<?php
	namespace org\kahikai\database\mysql;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252"/>
<meta name="author" content="Ch4mp"/>
<link rel="shortcut icon" href="../../../../../favicon.ico" type="image/x-icon"/> 
<link rel="icon" href="../../../../../favicon.ico" type="image/x-icon"/>
<title>MysqlGeneDao test</title>
</head>
<body>
<?php
	require_once '../../../../../org/kahikai/database/mysql/MysqlAliasDao.php';
	require_once '../../../../../org/kahikai/database/mysql/MysqlGeneDao.php';
	require_once '../../../../../org/kahikai/database/mysql/MysqlLanguageDao.php';
	
	use org\kahikai\database\mysql\MysqlAliasDao;
	use org\kahikai\database\mysql\MysqlGeneDao;
	use org\kahikai\database\mysql\MysqlLanguageDao;
	
	$languageDao = new MysqlLanguageDao();
	$aliasDao = new MysqlAliasDao($languageDao);
	$geneDao = new MysqlGeneDao($aliasDao);
	
	echo "<h1>getAll()</h1>\n";
	echo "<p>";
	foreach($geneDao->getAll() as $speciesId => $speciesGenes) {
		echo "Species#$speciesId genes: ";
		$firstGene = true;
		foreach($speciesGenes as $gene) {
			if($firstGene) {
				$firstGene = false;
			} else {
				echo ', ';
			}
			echo "($gene->id, $gene->name, [";
			$firstAlias = true;
			foreach($gene->aliases as $alias) {
				if($firstAlias) {
					$firstAlias = false;
				} else {
					echo ', ';
				}
				echo $alias->name;
			}
			echo "])";
		}
		echo "<br/>\n";
	}
	echo "</p>\n";
	
	echo "<h1>getById(1)</h1>\n";
	echo "<p>";
	$gene = $geneDao->getById(1);
	echo "$gene->id: $gene->name (";
	$first = true;
	foreach($gene->aliases as $alias) {
		if($first) {
			$first = false;
		} else {
			echo ', ';
		}
		echo $alias->name;
	}
	echo ")<br/>\n";
	echo "</p>\n";
	
	echo "<h1>getById(-1)</h1>\n";
	$gene = $geneDao->getById(-1);
	echo "<p>" . (isset($gene) ? "Shouldn't be set" : 'null') . "</p>\n";
	
	echo "<h1>getBySpeciesId(1)</h1>\n";
	echo "<p>";
	foreach($geneDao->getBySpeciesId(1) as $gene) {
		echo "$gene->id: $gene->name (";
		$first = true;
		foreach($gene->aliases as $alias) {
			if($first) {
				$first = false;
			} else {
				echo ', ';
			}
			echo $alias->name;
		}
		echo ")<br/>\n";
	}
	echo "</p>\n";
	
	echo "<h1>getBySpeciesId(-1)</h1>\n";
	echo "<p>";
	foreach($geneDao->getBySpeciesId(-1) as $gene) {
		echo "$gene->id: $gene->name (";
		$first = true;
		foreach($gene->aliases as $alias) {
			if($first) {
				$first = false;
			} else {
				echo ', ';
			}
			echo $alias->name;
		}
		echo ")<br/>\n";
	}
	echo "</p>\n";
?>
</body>
</html>